#include "Block.h"
//

using namespace std;
using namespace sf;

// Constructeur
Block::Block(int x, int y, string img, bool wall, bool act) {
	this->x			= x;
	this->y			= y;
	imgBlock.Create(32, 32, Color::Green);
	imgBlock.SetSmooth(false);
	if (img != "") {
		img = "Images/grounds/" + img + ".png";
		this->imgBlock.LoadFromFile(img);
	}
	this->wall		= wall;
	this->active	= act;
	this->pnj = false;
	this->rencontrePossible = false;

	this->bords.left = false;
	this->bords.top = false;
	this->bords.bottom = false;
	this->bords.right = false;

	this->teleport.dir = false;


}

bool Block::isActive() {
	return active;
}

bool Block::isBlocked() {
	return wall or pnj;
}

// Getters
int	Block::getPositionX() {
	return x;
}

int	Block::getPositionY() {
	return y;
}

Image Block::getImage() {
	return imgBlock;
}

// Setters
void Block::setImage(string img) {
	Image temp;
	temp.SetSmooth(false);
	img = "Images/" + img + ".png";
	temp.LoadFromFile(img);
	if (active)
		imgBlock.Copy(temp, 0, 0, IntRect(0, 0, 32, 32), true);
	else
		imgBlock = temp;
}

void Block::setImage(Image * img) {
	img->SetSmooth(false);
	if (active)
		imgBlock.Copy(*img, 0, 0, IntRect(0, 0, 32, 32), true);
	else
		imgBlock = *img;
}

void Block::setActive() {
	active = true;
}

void Block::setCoords(int x, int y) {
	this->x = x;
	this->y = y;
}

void Block::setBlocked() {
	wall = true;
}

void Block::setUnblocked() {
	wall = false;
}

void Block::setPnj(bool b)
{
    pnj = b;
}
bool Block::getPnj()
{
    return pnj;
}

bool Block::isPossible() {
    return rencontrePossible;
}

void Block::setRencontre(bool b)
{
    rencontrePossible = b;
}

bool Block::canGoOn(int direction) {
	return		( direction == MOVE_RIGHT && ! bords.left )
			||	( direction == MOVE_LEFT && ! bords.right)
			||	( direction == MOVE_UP && ! bords.bottom )
			||	( direction == MOVE_DOWN && ! bords.top );
}

void Block::setDir(string map, int dirX, int dirY) {
	teleport.dir = true;

	if ( map == "base" )
		teleport.map = "map.txt";
	else
		teleport.map = "Maps/" + map;

	teleport.x = dirX;
	teleport.y = dirY;
}

bool Block::isTeleport() {
	return teleport.dir;
}

Dir Block::getTeleport() {
	return teleport;
}
